<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript" src="resources/js/jquery-1.7.1.js"></script>
<script type="text/javascript">
	$(document).ready(
		function() {
			$.ajax({
				url: "visualizzaOrdiniUser.htm",
				type: "post",
				data: ({
					type: "ordini"
				}),
				success: function(res) {
					if(res == null || res == "undefined" || res == "") {
						$("#table").html("<tr><td><h2>Nessun Ordine o Stampa</h2></td></tr>");
						return false;
					}
					var list = res.split("#");
					for(var i = 0; i < list.length - 1; i++) {
						if(list[i].split("*")[0] != "null")
							$("#table").append("<tr onmouseup='price(\"" + $("#select").val() + "\", " + list[i].split("*")[1] + ", " + list[i].split("*")[2] + ", " + list[i].split("*")[3] + ")'><td>" + list[i].split("*")[0] + "</td><td>" + list[i].split("*")[1] + "</td><td>" + list[i].split("*")[2] + "</td><td>" + list[i].split("*")[3] + "</td><td>" + list[i].split("*")[4] + "</td></tr>");
						else
							$("#table").append("<tr onmouseup='price(\"" + $("#select").val() + "\", " + list[i].split("*")[1] + ", " + list[i].split("*")[2] + ", " + list[i].split("*")[3] + ")'><td>" + list[i].split("*")[5] + "</td><td>" + list[i].split("*")[1] + "</td><td>" + list[i].split("*")[2] + "</td><td>" + list[i].split("*")[3] + "</td><td>" + list[i].split("*")[4] + "</td></tr>");
					}
				}
			});
		}
	);
	
	$("#select").change(
		function() {
			$("#table").empty();
			$.ajax({
				url: "visualizzaOrdiniUser.htm",
				type: "post",
				data: ({
					type: $("#select").val()
				}),
				success: function(res) {
					if(res == null || res == "undefined" || res == "") {
						$("#table").html("<tr><td><h2>Nessun Ordine o Stampa</h2></td></tr>");
						return false;
					}
					var list = res.split("#");
					$("#table").append("<tr><td>Nome</td><td>Prezzo Ordine</td><td>Prezzo Stampa</td><td>Quantit&agrave;</td><td>Data</td></tr>");
					for(var i = 0; i < list.length - 1; i++) {
						if(list[i].split("*")[0] != "null")
							$("#table").append("<tr onmouseup='price(\"" + $("#select").val() + "\", " + list[i].split("*")[1] + ", " + list[i].split("*")[2] + ", " + list[i].split("*")[3] + ")'><td>" + list[i].split("*")[0] + "</td><td>" + list[i].split("*")[1] + "</td><td>" + list[i].split("*")[2] + "</td><td>" + list[i].split("*")[3] + "</td><td>" + list[i].split("*")[4] + "</td></tr>");
						else
							$("#table").append("<tr onmouseup='price(\"" + $("#select").val() + "\", " + list[i].split("*")[1] + ", " + list[i].split("*")[2] + ", " + list[i].split("*")[3] + ")'><td>" + list[i].split("*")[5] + "</td><td>" + list[i].split("*")[1] + "</td><td>" + list[i].split("*")[2] + "</td><td>" + list[i].split("*")[3] + "</td><td>" + list[i].split("*")[4] + "</td></tr>");
					}
				}
			});
		}
	);
	
	function price(tipo, ordine, stampa, quantita) {
		if(tipo == "ordini") {
			$("#price").html(ordine * quantita + "&euro;");
		} else {
			$("#price").html(stampa + "&euro;");
		}
	}
</script>
<title>Insert title here</title>
</head>
<body>
	<div class="box">
		<select id="select">
			<option id="ordini" value="ordini">Ordini</option>
			<option id="stampe" value="stampe">Stampe</option>
		</select>
		<table id="table" title="Calcola spesa cliccando su un item">
			<tr>
				<td>Nome</td><td>Prezzo Ordine</td><td>Prezzo Stampa</td><td>Quantit&agrave;</td><td>Data</td>
			</tr>
		</table>
		<div id="price"></div>
	</div>
</body>
</html>